package edu.ycu.aladdin.web.config.oauth;

import edu.ycu.aladdin.web.utils.StringUtils;
import lombok.Data;
import lombok.Getter;
import lombok.Setter;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

/**
 * 百度oauth授权参数
 *
 * @author <a href="mailto:wangruihuano@gmail.com">王瑞环</a>
 * @since 1.0
 */
@Component
@ConfigurationProperties(prefix = "aladdin.oauth.baidu")
public class BaiduOauthConfig {

    @Getter
    private String api_key;

    @Getter
    private String secret_key;

    @Getter
    private String redirect_uri;

    @Getter
    private String guid_url;

    private String user_info_url;

    private String access_url;

    public String getUser_info_url(String access_token) {
        return user_info_url.replace("{{access_token}}",access_token);
    }

    public String getAccess_url(String code) {
        return access_url.replace("{{code}}",code);
    }

    public void setGuid_url(String guid_url) {
        this.guid_url =StringUtils.removeAllBlankChar(guid_url);
    }

    public void setAccess_url(String access_url) {
        this.access_url = StringUtils.removeAllBlankChar(access_url);
    }

    public void setApi_key(String api_key) {
        this.api_key = api_key;
    }

    public void setSecret_key(String secret_key) {
        this.secret_key = secret_key;
    }

    public void setRedirect_uri(String redirect_uri) {
        this.redirect_uri = StringUtils.removeAllBlankChar(redirect_uri);
    }

    public void setUser_info_url(String user_info_url) {
        this.user_info_url = StringUtils.removeAllBlankChar(user_info_url);
    }

    @Override
    public String toString() {
        return "BaiduOauthConfig{" +
                "api_key='" + api_key + '\'' +
                ", secret_key='" + secret_key + '\'' +
                ", redirect_uri='" + redirect_uri + '\'' +
                ", guid_url='" + guid_url + '\'' +
                ", user_info_url='" + user_info_url + '\'' +
                ", access_url='" + access_url + '\'' +
                '}';
    }
}

